package cn.enilu.flash.mobile.controller;

import cn.enilu.flash.bean.entity.shop.ShopUser;
import cn.enilu.flash.bean.vo.JwtUser;
import cn.enilu.flash.bean.vo.UserInfo;
import cn.enilu.flash.bean.vo.front.Ret;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.bean.vo.shop.WechatInfo;
import cn.enilu.flash.bean.vo.shop.WechatLoginResult;
import cn.enilu.flash.bean.vo.shop.WechatUserInfoParam;
import cn.enilu.flash.cache.CacheDao;
import cn.enilu.flash.security.UserService;
import cn.enilu.flash.service.api.WeixinService;
import cn.enilu.flash.service.shop.ShopUserService;
import cn.enilu.flash.utils.Maps;
import cn.enilu.flash.web.controller.BaseController;
import cn.hutool.crypto.SecureUtil;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.Map;

/**
 * @author ：enilu
 * @date ：Created in 2020/6/6 20:32
 */
@RestController
@RequestMapping("/wechat")
public class WeChatController extends BaseController {
    @Autowired
    private ShopUserService shopUserService;
    @Autowired
    private WeixinService weixinService;
    @Autowired
    private CacheDao cacheDao;

    @GetMapping("/login")
    public Object loginByCode(String code) throws WxErrorException {
        WechatLoginResult wechatLoginResult = weixinService.getWechatInfoByCode(code);
        return Rets.success(wechatLoginResult);
    }

    @PostMapping("/perfect/info")
    public Object perfectUserInfo(@RequestBody WechatUserInfoParam wechatUserInfo) {
        UserInfo userInfo = weixinService.perfectUserInfo(wechatUserInfo, getIdUser());
        return Rets.success(userInfo);
    }

    @RequestMapping(value = "getWxSign", method = RequestMethod.POST)
    public Object getWxSign(@RequestParam("url") String url) {
        Map<String, String> map = weixinService.getSign(url);
        return Rets.success(map);
    }
}
